require(["dojo/parser", "dijit/Dialog", "dijit/layout/BorderContainer", "dijit/layout/TabContainer", "dijit/layout/ContentPane", "dijit/Tree", "dijit/tree/ForestStoreModel", "ext/data/DominoItemFileReadStore", "dojox/layout/ExpandoPane", "dojox/xml/parser"]);
var gEditor = null,
gWFProcessXML = null,
gRulesXML = null;
function Application(a) {
	try {
		if (!Client.isBrowserSupported()) {
			Utils.alert('\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\uFF01')
		} else {
			var b = Utils.load(a).getDocumentElement();
			var c = new Editor(b);
			c.dblClickAction = "showProperties"
		}
	} catch(e) {
		Utils.alert('\u4E0D\u80FD\u88C5\u8F7D\u6D41\u7A0B: ' + e.message);
		throw e;
	};
	return c;
};
function onInit(f) {
	gWFProcessXML = dojox.xml.parser.parse(dojo.byId("WFProcessXML").value.replace(/[\r\n]/g, "")).documentElement;
	dojo.xhrGet({
		url: BasePath + "/config/rules.xml",
		preventCache: false,
		handleAs: "xml",
		load: function(a) {
			gRulesXML = a
		}
	});
	gEditor = f;
	f.graph.setTooltips(false);
	ConnectionHandler.prototype.connectImage = new Image(BasePath + '/images/connector.gif', 16, 16);
	GraphHandler.prototype.guidesEnabled = true;
	//f.graph.connectionHandler.setEnabled(true);

	f.graph.setConnectable(true);
	//f.graph.setResizeContainer(true);
	var g = function(a, b, c, d) {
		dojo.query(dojo.create('img', {
			src: BasePath + "/images/" + a + ".gif",
			title: b
		})).addClass("ToolbarMode").onclick(c).place("#" + d)
	};
	if (gbIsCreateNew) {
		g("New", "\u65B0\u5EFA\u6D41\u7A0B", "OpenWF", "basicActions");
		g("Edit", "\u7F16\u8F91\u6D41\u7A0B\u5C5E\u6027", "EditWF", "attrWF")
	}
	g("Save", "\u4FDD\u5B58\u6587\u6863", "SaveWF", "basicActions");
	g("Grid", "\u7F51\u683C\u7EBF", "showGrid", "mainActions");
	var h = function(a) {
		return function() {
			wfRemoveCheck(a.graph)
		}
	};
	g("Delete", "\u5220\u9664\u8282\u70B9", h(f), "mainActions");
	var h = function(a, b) {
		return function() {
			a.execute(b)
		}
	};
	g("SelectAll", "\u9009\u62E9\u6240\u6709\u8282\u70B9", h(f, "selectAll"), "mainActions");
	g("SelectNone", "\u53D6\u6D88\u5DF2\u9009\u8282\u70B9", h(f, "selectNone"), "mainActions");
	g = h = null;
	var i = dojo.byId('GraphXML');
	var j = Utils.parseXml(dojo.byId('WFGraphXML').value.replace(/\r|\n/g, "").replace(/@line@/g, "&#xa;"));
	var k = new Codec(j);
	k.decode(j.documentElement, f.graph.getModel());
	if (Client.IS_IE) {
		document.selection.empty()
	}
	var l = dojo.byId('source');
	l.checked = false;
	var m = f.graph.container;
	var n = function(a) {
		if (l.checked) {
			m.style.display = 'none';
			dojo.style("toolbar", "display", "none");
			dojo.style("mainActions", "display", "none");
			i.style.display = 'inline';
			var b = new Codec(Utils.createXmlDocument());
			var c = b.encode(a.graph.getModel());
			i.value = Utils.getPrettyXml(c);
			i.originalValue = i.value;
			i.focus()
		} else {
			m.style.display = '';
			if (i.value != i.originalValue) {
				var d = Utils.parseXml(i.value);
				var e = new Codec(d);
				e.decode(d.documentElement, a.graph.getModel())
			}
			i.originalValue = null;
			if (Client.IS_IE) {
				document.selection.empty()
			}
			dojo.style("toolbar", "display", "inline");
			dojo.style("mainActions", "display", "inline");
			i.style.display = 'none';
			i.blur();
			a.graph.container.focus()
		}
	};
	f.addAction('switchView', n);
	Event.addListener(l, 'click',
	function() {
		f.execute('switchView')
	});
	dojo.style("graph", "visibility", "visible")
};
function showGrid() {
	dojo.style("graph", "backgroundImage", dojo.style("graph", "backgroundImage") == "none" ? 'url(' + BasePath + '/images/bgGraph.gif)': '')
};
function wfInitNode(m) {
	if (dijit.byId('nodeDlg')) {
		var n = dojo.connect(dijit.byId("btnSave"), "onClick",
		function() {
			wfSaveNode(m);
			dojo.disconnect(n)
		});
		var o = dojo.connect(dijit.byId("btnCancel"), "onClick",
		function() {
			dijit.byId('nodeDlg').hide();
			dojo.disconnect(o)
		});
		var p = m.getStyle(),
		cellId = m.getId();
		dojo.byId('WFNodeId').value = cellId;
		dojo.byId('WFNodeName').value = gEditor.graph.getLabel(m) == undefined ? "": gEditor.graph.getLabel(m);
		p = m.isEdge() ? "Router": p;
		if (p != "Swimlane") {
			var q = dojo.query(cellId, gWFProcessXML);
			if (q.length > 0) {
				var r = dojo.query(p + ">*", gRulesXML);
				if (r.length > 0) {
					dojo.forEach(r,
					function(h) {
						try {
							var i = dojo.query(cellId + ">" + h.nodeName, gWFProcessXML);
							if (i.length > 0) {
								var j = dojo.byId(h.nodeName),
								tmpValue = i[0].getAttribute("value");
								switch (h.getAttribute("type")) {
								case "checkbox":
									if (tmpValue == h.getAttribute("active")) j.checked = true;
									break;
								case "list":
									var k = dojo.query("tr", i[0]);
									if (k.length > 0) {
										dojo.forEach(dojo.query("tbody>tr", j),
										function(f, g) {
											dojo.forEach(k,
											function(d) {
												var e = dojo.query("td", d);
												if (parseInt(e[0].getAttribute("value"), 10) == g) {
													dojo.forEach(dojo.query("input,select", f),
													function(b, c) {
														if (c == 0) {
															b.checked = true
														} else {
															if (b.tagName.toLowerCase() == "select") {
																dojo.forEach(b.options,
																function(a) {
																	if (a.value == e[c].getAttribute("value")) {
																		a.selected = true
																	}
																})
															} else {
																b.value = e[c].getAttribute("value")
															}
														}
													})
												}
											})
										})
									}
									break;
								case "selectmore":
									var l = new Array();
									l = tmpValue.split("|");
									dojo.empty(j);
									dojo.forEach(l,
									function(a) {
										j.add(new Option(a.split("^")[0], a))
									});
									break;
								case "selectone":
									if (j.tagName.toLowerCase() == "select") {
										dojo.forEach(j.options,
										function(a) {
											if (a.value == tmpValue) {
												a.selected = true
											}
										})
									}
									break;
								case "rtf":
									tmpValue = dojox.xml.parser.textContent(i[0]);
									j.value = tmpValue;
									break;
								default:
									j.value = tmpValue;
									if(h.nodeName=="WFFieldStatus"){
										j.value=dojo.toJson(dojo.fromJson(tmpValue),true)
									}else if(h.nodeName=="WFNodeName"){
										j.value=tmpValue.replace(/@line@/g,"\n")
									}
								}
							}
						} catch(e) {}
					})
				}
			}
		}
	}
};
function wfSaveNode(l) {
	if (dijit.byId('nodeDlg')) {
		var m = dojo.byId('WFNodeName').value,
		cellStyle = l.isEdge() ? "Router": l.getStyle();
		if (cellStyle != "Swimlane") {
			var n = dojo.query(l.getId(), gWFProcessXML),
			arrRules = dojo.query(cellStyle + ">*", gRulesXML);
			if (arrRules.length > 0) {
				var o = n.length < 1;
				var p = function(j, k) {
					dojo.forEach(j,
					function(f) {
						try {
							var g = dojo.query(f.nodeName, k),
							o = g.length < 1,
							tmpNode = o ? dojox.xml.parser.parse("<" + f.nodeName + "/>").documentElement: g[0];
							var h = dojo.byId(f.nodeName),
							tmpValue = "",
							isRTF = false,
							isNoList = true;
							switch (f.getAttribute("type")) {
							case "checkbox":
								if (h.checked) {
									tmpValue = h.value
								};
								break;
							case "list":
								dojo.empty(tmpNode);
								dojo.forEach(dojo.query("tr>td>input:checked", h),
								function(c) {
									var d = dojo.query("input,select", c.parentNode.parentNode);
									var e = dojox.xml.parser.parse("<tr/>").documentElement;
									dojo.forEach(d,
									function(a) {
										var b = dojox.xml.parser.parse("<td/>").documentElement,
										tmpValue = a.value;
										if (a.tagName.toLowerCase() == "select") {
											tmpValue = a.options[a.selectedIndex].value
										}
										b.setAttribute("value", tmpValue);
										dojo.place(b, e)
									});
									dojo.place(e, tmpNode)
								});
								isNoList = false;
								break;
							case "selectmore":
								var i = new Array();
								dojo.forEach(h.options,
								function(a) {
									i.push(a.value)
								});
								tmpValue = i.join("|");
								break;
							case "selectone":
								if (h.tagName.toLowerCase() == "select") {
									tmpValue = h.options[h.selectedIndex].value
								}
								break;
							case "rtf":
								isRTF = true;
								tmpValue = h.value;
								break;
							default:
								tmpValue = h.value
							}
							tmpValue = dojo.trim(tmpValue);
							if (isRTF) {
								if (tmpValue != "") {
									dojo.empty(tmpNode);
									dojo.place(gWFProcessXML.createCDATASection(tmpValue), tmpNode)
								}
								isRTF = false
							} else {
								if (isNoList) {
									if (tmpValue != "") {
										tmpNode.setAttribute("value", tmpValue)
									} else {
										dojo.destroy(tmpNode)
									}
								}
							}
						} catch(e) {}
						if (o) {
							if (tmpValue != "" || isNoList == false) {
								dojo.place(tmpNode, k)
							}
						}
						isNoList = true
					})
				};
				var q = o ? dojox.xml.parser.parse("<" + l.getId() + "/>").documentElement: dojo.query(l.getId(), gWFProcessXML)[0];
				if (l.isEdge()) {
					var r = l.getTerminal(true).getId(),
					tNodeId = l.getTerminal(false).getId();
					q.setAttribute("source", r);
					q.setAttribute("target", tNodeId)
				}
				q.setAttribute("nType", cellStyle);
				if (o) {
					dojo.place(q, gWFProcessXML)
				}
				p(arrRules, q)
			}
		}
		dijit.byId('nodeDlg').hide()
	}
}
function wfLine(b, c) {
	dojo.forEach(b.graph.getSelectionCells(),
	function(a) {
		if (a != null && b.graph.model.isEdge(a)) {
			b.graph.setCellStyle(c,[a])
		}
	});
}
function wfRemoveCheck(a) {
	if (confirm("\u60A8\u597D\uFF1A\n\n\u60A8\u786E\u4FE1\u9700\u8981\u5220\u9664\u6240\u9009\u5BF9\u8C61\uFF1F\n\n\u6CE8\u610F\uFF1A\u5220\u9664\u540E\u5C06\u4E0D\u53EF\u518D\u6062\u590D\uFF01\u8BF7\u60A8\u8C28\u614E\u64CD\u4F5C\uFF01\uFF01\uFF01")) {
		//a.model.cellRemoved(a.model)
		a.removeCells();
	}
}
function wfCreateNode(a, b, c, d, e) {
	var f = a.graph;
	//if (f.canImport(b)) {
	if (f.canImportCell(b)) {
		var g = Utils.convertPoint(f.container, c.clientX, c.clientY);
		f.model.prefix = "",
		bS = e == "S",bE = e == "E";
		if (bS && f.model.cells["S"]) {
			Utils.alert("\u4EC5\u5141\u8BB8\u521B\u5EFA\u4E00\u4E2A<\u5F00\u59CB\u8282\u70B9>\uFF01");
			return
		} else {
			if (bS) {
				b.setId("S")
			} else if(bE){
				b.setId(e + +(new Date()).getTime())
			}
		}
		f.model.prefix="N";
		return a.addVertex(d, b, g.x, g.y)
	}
}
function wfRemoveNode(a) {
	var b = dojo.query(a.getId(), gWFProcessXML);
	if (b.length > 0) {
		dojo.destroy(b[0])
	}
}
function EditWF() {
	var a = dijit.byId('oWFDlg');
	a.show()
}
function fnClearValue(b) {
	dojo.forEach(dojo.query("input", b.parentNode.parentNode),
	function(a) {
		a.value = ""
	})
}
function fnSelectAlignStyle(a) {
	dojo.byId("AlignStyle").value = a.value
};
Utils.alert = function(b) {
	try {
		if (dojo) {
			var c = b.replace(/\n/g, "<br/>");
			if (dijit.byId('dlgAlert')) {
				dijit.byId('dlgAlert').set("content", c);
				dijit.byId('dlgAlert').show()
			} else {
				var d = new dijit.Dialog({
					title: "\u53CB\u60C5\u63D0\u793A",
					id: "dlgAlert",
					content: c,
					onKeyDown: function(a) {
						key = a.keyCode;
						if (key == dojo.keys.SPACE || key == dojo.keys.ENTER) {
							this.onCancel()
						}
					},
					onHide: function() {
						this.destroyDescendants()
					}
				});
				dojo.body().appendChild(d.domNode);
				d.show()
			}
		}
	} catch(e) {
		alert(b)
	}
};
Editor.prototype.showProperties = function(a) {
	a = a || this.graph.getSelectionCell();
	if (a == null) {
		a = this.graph.getCurrentRoot();
		if (a == null) {
			a = this.graph.getModel().getRoot()
		}
	}
	if (a != null && this.graph.isEnabled()) {
		var b = dijit.byId('nodeDlg');
		if (b == null) {
			b = new dijit.Dialog({
				title: "\u53CB\u60C5\u63D0\u793A",
				id: "nodeDlg"
			});
			dojo.body().appendChild(b.domNode)
		};
		var c = a.getStyle() == null ? "": a.getStyle().split(";")[0],
		isOrgin = a.isEdge() && a.getTerminal(true).getId() == "S" ? true: false;
		if (c == "Start" || c == "End" || isOrgin) {
			Utils.alert("\u8BE5\u8282\u70B9\u65E0\u9700\u7F16\u8F91\uFF01\n")
		} else {
			b.set({
				href: BasePath + "/config/" + (a.isEdge() ? "Router": c) + ".html",
				onFocus: function() {
					dojo.query("div.Tooltip").style({
						visibility: "hidden"
					})
				},
				onDownloadEnd: function() {
					wfInitNode(a)
				},
				onHide: function() {
					gEditor.graph.labelChanged(a, dojo.byId('WFNodeName').value)
				}
			});
			b.show()
		}
	}
};
Cell.prototype.remove = function(a) {
	var b = null;
	if (this.children != null && a >= 0) {
		b = this.getChildAt(a);
		if (b != null) {
			this.children.splice(a, 1);
			b.setParent(null);
			wfRemoveNode(b)
		}
	}
	return b
};
/*
VertexHandler.prototype.init = function() {
    this.graph = this.state.view.graph;
    this.selectionBounds = this.getSelectionBounds(this.state);
    this.bounds = new Rectangle(this.selectionBounds.x, this.selectionBounds.y, this.selectionBounds.width, this.selectionBounds.height);
    this.selectionBorder = this.createSelectionShape(this.bounds);
    this.selectionBorder.dialect = this.graph.dialect != Constants.DIALECT_SVG ? Constants.DIALECT_VML: Constants.DIALECT_SVG;
    this.selectionBorder.pointerEvents = !1;
    this.selectionBorder.init(this.graph.getView().getOverlayPane());
    Event.redirectMouseEvents(this.selectionBorder.node, this.graph, this.state);
    this.graph.isCellMovable(this.state.cell) && (this.selectionBorder.node.style.cursor = Constants.CURSOR_MOVABLE_VERTEX);
    if (0 >= GraphHandler.prototype.maxCells || this.graph.getSelectionCount() < GraphHandler.prototype.maxCells) {
        //var a = this.graph.isCellResizable(this.state.cell);
        this.sizers = [];
		with(this.graph) {
			var bSwimlane = isSwimlane(this.state.cell),
				bCellResizable = isCellResizable(this.state.cell),
				bSwimlaneResizable = isSwimlaneResizable(this.state.cell),
				bLabelMovable=isLabelMovable(this.state.cell)
		};
        //if (a || this.graph.isLabelMovable(this.state.cell) && 2 <= this.state.width && 2 <= this.state.height) {
        if ((!bSwimlane&&bCellResizable) || (bSwimlane&&bSwimlaneResizable) || bLabelMovable && 2 <= this.state.width && 2 <= this.state.height) {
            var b = 0;
            bCellResizable && (this.singleSizer || (this.sizers.push(this.createSizer("nw-resize", b++)), this.sizers.push(this.createSizer("n-resize", b++)), this.sizers.push(this.createSizer("ne-resize", b++)), this.sizers.push(this.createSizer("w-resize", b++)), this.sizers.push(this.createSizer("e-resize", b++)), this.sizers.push(this.createSizer("sw-resize", b++)), this.sizers.push(this.createSizer("s-resize", b++))), this.sizers.push(this.createSizer("se-resize", b++)));
            var a = this.graph.model.getGeometry(this.state.cell);
            null != a && (!a.relative && !bSwimlane && bLabelMovable) && (this.labelShape = this.createSizer(Constants.CURSOR_LABEL_HANDLE, Event.LABEL_HANDLE, Constants.LABEL_HANDLE_SIZE, Constants.LABEL_HANDLE_FILLCOLOR), this.sizers.push(this.labelShape))
        } else this.graph.isCellMovable(this.state.cell) && (!bCellResizable && 2 > this.state.width && 2 > this.state.height) && (this.labelShape = this.createSizer(Constants.CURSOR_MOVABLE_VERTEX, null, null, Constants.LABEL_HANDLE_FILLCOLOR), this.sizers.push(this.labelShape))
    }
    if (this.graph.isEnabled() && this.rotationEnabled && this.graph.isCellRotatable(this.state.cell) && (0 >= GraphHandler.prototype.maxCells || this.graph.getSelectionCount() < GraphHandler.prototype.maxCells) && 2 < this.state.width && 2 < this.state.height) this.rotationShape = this.createSizer(this.rotationCursor, Event.ROTATION_HANDLE, Constants.HANDLE_SIZE + 3, Constants.HANDLE_FILLCOLOR),
    this.sizers.push(this.rotationShape);
    this.redraw();
    this.constrainGroupByChildren && this.updateMinBounds()
};
Graph.prototype.swimlaneResizable = true;
Graph.prototype.isSwimlaneResizable = function(a) {
	return this.swimlaneResizable && !this.isLocked(a)
};
*/
function AddValue(b) {
	b = dojo.trim(dojo.isArray(b) ? b[0] : b);
	if (b != "") {
		var c = dojo.byId("WFempTarget");
		if (dojo.some(dojo.byId("WFempTarget"),
		function(a) {
			return a.value == b
		})) {
			alert(b.split("^")[0] + " \u5DF2\u5B58\u5728\uFF01")
		} else {
			c.options[c.length] = new Option(b.split("^")[0], b)
		}
	}
}
function DelValue(a) {
	if (a.selectedIndex >= 0) {
		a.remove(a.selectedIndex);
		DelValue(a)
	}
}
function fnAlternateSelectValue(s, t, b, c) {
	var d = dojo.query("#" + t + " > *");
	if (b && d.length > 0) {
		dojo.empty(t)
	};
	dojo.forEach(dojo.query("#" + s + " > *"),
	function(a, b) {
		dojo.place(dojo.clone(a), t)
	});
	var e = dijit.byId(c);
	if (e && b) {
		e.hide()
	}
}
var gJsonField = null;
function fnAssignFieldStatus() {
	if (dojo.byId("WFMainForm").value.replace(/\s/g, "") == "") {
		Utils.alert("\u8BF7\u586B\u5199\u6216\u9009\u62E9\u8868\u5355\u540D\u79F0\uFF01");
		return
	}
	var h = dojo.byId("WFFieldStatus").value.replace(/\s/g, "");
	if (h == "") {
		h = "{}";
	}
	gJsonField = dojo.fromJson(h);
	var i = function() {
		dojo.xhrGet({
			url: encodeURI("/" + gCurDB + "/pgReadField?OpenPage&N=" + dojo.byId("WFModule").value + "-" + dojo.byId("WFMainForm").value),
			handleAs: "text",
			preventCache: true,
			load: function(c) {
				if (c != "") {
					var d = eval("[" + c + "]");
					dojo.forEach(d,
					function(a) {
						var b = a.split("|")[0],
						id = "$$" + a.split("|")[1],
						Data = '<table cellspacing=1 cellpadding=0><tr><td class="tdTitle">' + b + '</td><td class="tdInput"><select id="' + id + '" onchange="fnChangeStatus(this)"><option value="0">\u53EF\u7F16\u8F91</option><option value="1">\u53EA\u8BFB</option><option value="2">\u9690\u85CF</option><option value="3">\u5FC5\u586B</option><option value="4">\u4EC5\u90E8\u5206\u53EF\u89C1</option><option value="5">\u90E8\u5206\u53EF\u89C1\u5FC5\u586B</option></select></td></tr></table>';
						dojo.addClass(dojo.create("div", {
							innerHTML: Data
						},
						"WFFormContainer", "last"), "dvAllIdea")
					});
					try {
						for (f in gJsonField) {
							var g = dojo.byId("$$" + f);
							if (g) {
								if (typeof(gJsonField[f].e) != "undefined") {
									g.selectedIndex = 0
								} else if (typeof(gJsonField[f].r) != "undefined") {
									g.selectedIndex = 1
								} else if (typeof(gJsonField[f].h) != "undefined") {
									g.selectedIndex = 2
								} else if (typeof(gJsonField[f].w) != "undefined") {
									g.selectedIndex = 3
								} else if (typeof(gJsonField[f].s) != "undefined") {
									g.selectedIndex = 4
								} else if (typeof(gJsonField[f].m) != "undefined") {
									g.selectedIndex = 5
								}
							} else {
								delete gJsonField[f]
							}
						}
					} catch(e) {}
				}
			}
		})
	};
	var j = dijit.byId('oFieldDlg');
	if (j == null) {
		j = new dijit.Dialog({
			title: "\u8868\u5355\u5B57\u6BB5\u8BBE\u7F6E",
			id: "oFieldDlg",
			onDownloadEnd: function() {
				i()
			},
			onHide: function() {
				gJsonField = null;
				this.destroyDescendants()
			}
		});
		dojo.body().appendChild(j.domNode)
	}
	j.set("href", "/" + gCurDB + "/htmReadField?ReadForm");
	j.show()
}
function fnChangeStatus(b) {
	var c = b.id.substr(2);
	if (gJsonField[c]) {} else {
		gJsonField[c] = {}
	}
	switch (b.value) {
	case "0":
		break;
	case "1":
		break;
	case "2":
		break;
	case "3":
		// var d = dijit.byId('oMustTipDlg');
		// if (d == null) {
			// d = new dijit.Dialog({
				// title: "\u5FC5\u586B\u63D0\u793A",
				// id: "oMustTipDlg",
				// onHide: function() {
					// this.destroyRecursive()
				// }
			// });
			// dojo.body().appendChild(d.domNode)
		// }
		// d.set("content", "<table class='tbWFFormContainer' cellspacing=0 cellpadding=0><tr><td align='center'><input type=text style='width:98%' id='FieldWriteInput'/></td></tr><tr><td align='right'><button dojoType='dijit.form.Button' type='button' id='FieldWriteSave'>\u786E\u5B9A</button>&nbsp;&nbsp;<button dojoType='dijit.form.Button' type='button' onclick=\"dijit.byId('oMustTipDlg').hide()\">\u53D6\u6D88</button>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>");
		// var e = dojo.connect(d, "onFocus",
		// function() {
			// fnAlternateFieldValue(c, "FieldWriteInput", false, "oMustTipDlg");
			// dojo.disconnect(e)
		// });
		// var f = dojo.connect(dijit.byId("FieldWriteSave"), "onClick",
		// function() {
			// if (dojo.trim(dojo.byId("FieldWriteInput").value) == "") {
				// alert("\u8BF7\u8F93\u5165\u63D0\u793A\u5185\u5BB9\uFF01");
				// return
			// }
			// fnAlternateFieldValue("FieldWriteInput", c, true, "oMustTipDlg");
			// dojo.disconnect(f)
		// });
		// d.show();
		break;
	default:
		var g = dijit.byId('oSelectDlg');
		if (g == null) {
			g = new dijit.Dialog({
				title: "\u9009\u62E9\u4EBA\u5458",
				id: "oSelectDlg",
				onHide: function() {
					this.destroyDescendants()
				}
			});
			dojo.body().appendChild(g.domNode)
		}
		g.set("href", "/" + gCurDB + "/htmWFSelectFieldUser?ReadForm");
		var h = dojo.connect(g, "onDownloadEnd",
		function() {
			fnAlternateFieldValue(c, "WFempTarget", false, "oSelectDlg");
			var a = dojo.connect(dijit.byId("FieldSave"), "onClick",
			function() {
				fnAlternateFieldValue("WFempTarget", c, true, "oSelectDlg");
				dojo.disconnect(a)
			});
			dojo.disconnect(h)
		});
		g.show()
	}
}
function fnAlternateFieldValue(s, t, b, c) {
	if (b) {
		var d = dojo.byId(s),
		objT = dojo.byId("$$" + t);
		if (d.tagName.toLowerCase() == "select") {
			var e = [];
			dojo.forEach(d.options,
			function(a) {
				e.push(a.value)
			});
			if (objT.value == "4") {
				gJsonField[t].s = e.join("|")
			} else {
				var f = dojo.byId("FieldSeeWriteInput").value;
				if (dojo.trim(f) == "") {
					alert("\u8BF7\u8F93\u5165\u63D0\u793A\u5185\u5BB9\uFF01");
					return
				}
				gJsonField[t].m = e.join("|") + "$$" + f
			}
		} else {
			gJsonField[t].w = d.value
		}
	} else {
		var d = dojo.byId("$$" + s),
		objT = dojo.byId(t);
		if (objT.tagName.toLowerCase() == "select") {
			dojo.empty(t);
			if (d.value == "4") {
				if (gJsonField[s] && gJsonField[s].s) {
					dojo.forEach(gJsonField[s].s.split("|"),
					function(a) {
						objT.add(new Option(a.split("^")[0], a))
					})
				}
			} else {
				if (gJsonField[s] && gJsonField[s].m) {
					var g = gJsonField[s].m.split("$$");
					dojo.forEach(g[0].split("|"),
					function(a) {
						objT.add(new Option(a.split("^")[0], a))
					});
					dojo.byId("FieldSeeWriteInput").value = g[1]
				}
			}
		} else {
			objT.value = typeof(gJsonField[s].w) != "undefined" ? gJsonField[s].w: ""
		}
	}
	var h = dijit.byId(c);
	if (h && b) {
		h.hide()
	}
}
function fnSaveFieldStatus() {
	var e = dojo.query("select", "oFieldDlg");
	if (e.length > 0) {
		dojo.forEach(e,
		function(a) {
			var b = a.id.substr(2),
			obj = {};
			var c = function(o, s) {
				return typeof(o[s]) != "undefined"
			};
			if (c(gJsonField, b)) {
				obj = gJsonField[b]
			} else {
				gJsonField[b] = obj
			}
			var d = c(obj, "e"),
			bh = c(obj, "h"),
			br = c(obj, "r"),
			bw = c(obj, "w"),
			bs = c(obj, "s"),
			bm = c(obj, "m");
			switch (a.value) {
			case "0":
				if (b.indexOf("ID_") > -1) {
					if (br) delete obj.r;
					if (bh) delete obj.h;
					if (bw) delete obj.w;
					if (bm) delete obj.m;
					if (bs) delete obj.s;
					obj.e = ""
				} else {
					delete gJsonField[b]
				}
				break;
			case "1":
				if (d) delete obj.e;
				if (bh) delete obj.h;
				if (bw) delete obj.w;
				if (bs) delete obj.s;
				if (bm) delete obj.m;
				obj.r = "";
				break;
			case "2":
				if (d) delete obj.e;
				if (br) delete obj.r;
				if (bw) delete obj.w;
				if (bs) delete obj.s;
				if (bm) delete obj.m;
				obj.h = "";
				break;
			case "3":
				if (d) delete obj.e;
				if (br) delete obj.r;
				if (bh) delete obj.h;
				if (bs) delete obj.s;
				if (bm) delete obj.m;
				obj.w = "";
				break;
			case "4":
				if (d) delete obj.e;
				if (br) delete obj.r;
				if (bh) delete obj.h;
				if (bw) delete obj.w;
				if (bm) delete obj.m;
				break;
			case "5":
				if (d) delete obj.e;
				if (br) delete obj.r;
				if (bh) delete obj.h;
				if (bw) delete obj.w;
				if (bs) delete obj.s;
				break;
			default:
			}
		})
	}
	var tmpJsonField = dojo.toJson(gJsonField, true);
	dojo.byId("WFFieldStatus").value =  tmpJsonField == "{}" ? "": tmpJsonField.replace(/"/g, "'");
	dijit.byId('oFieldDlg').hide()
}
function getPrettyXml(a, b, c) {
	var d = [];
	if (a != null) {
		b = b || '  ';
		c = c || '';
		if (a.nodeType == Constants.NODETYPE_TEXT) {
			d.push(a.nodeValue)
		} else {
			d.push(c + '<' + a.nodeName);
			var e = a.attributes;
			if (e != null) {
				for (var i = 0; i < e.length; i++) {
					var f = htmlEntities(e[i].nodeValue, "@line@");
					d.push(' ' + e[i].nodeName + '="' + f + '"')
				}
			}
			var g = a.firstChild;
			if (g != null) {
				d.push('>\n');
				while (g != null) {
					d.push(getPrettyXml(g, b, c + b));
					g = g.nextSibling
				}
				d.push(c + '</' + a.nodeName + '>\n')
			} else {
				d.push('/>\n')
			}
		}
	}
	return d.join('')
}
function htmlEntities(s, a) {
	s = s || '';
	s = s.replace(/&/g, '&amp;');
	s = s.replace(/"/g, '&quot;');
	s = s.replace(/\'/g, '&#39;');
	s = s.replace(/</g, '&lt;');
	s = s.replace(/>/g, '&gt;');
	if (a == null) {
		s = s.replace(/\n/g, '&#xa;')
	} else {
		s = s.replace(/\n/g, a)
	}
	return s
}

function OpenWF() {
	window.location = "/HTOA/workflow/workflow.jsp"
}
function SaveWF() {
	if(dojo.byId("menuId").value){
	}else{
		alert("请点击左侧，选择菜单");
		return;
	}
	var a = gEditor.graph.model,
	edge = a.getOutgoingEdges(a.cells["S"]);
	if (edge == "") {
		Utils.alert("\u6CA1\u6709\u5F00\u59CB\u8282\u70B9\u6216\u7ED3\u675F\u8282\u70B9");
		return
	};
	if (edge != null) {
		gWFProcessXML.setAttribute("OriginNode", edge[0].getTerminal(false).getId());
		gWFProcessXML.setAttribute("OriginRouter", edge[0].getId())
	};
	var b = new Codec(Utils.createXmlDocument());
	var c = b.encode(gEditor.graph.getModel());
	dojo.byId('WFGraphXML').value = getPrettyXml(c);
	dojo.byId('WFProcessXML').value = dojo.byId('WFGraphXML').value == '<GraphModel><root><Cell id="0"/><Cell id="1" parent="0"/></root></GraphModel>' ? "<Process/>": Utils.getPrettyXml(gWFProcessXML).replace(/\n+/g, "\n");
	var d = document.forms[0];
	if (gbIsCreateNew) {
		dojo.place("WFName", d);
		dojo.place("WFStatus", d);
		dojo.place("WFVersion", d);
		dojo.place("menuId", d);
	}
	d.submit()
}
function goSelectCurUser() {
	var a = dijit.byId('oWinDlg');
	if (a == null) {
		a = new dijit.Dialog({
			title: "\u9009\u62E9\u5904\u7406\u4EBA",
			id: "oWinDlg",
			onDownloadEnd: function() {
				fnAlternateSelectValue("WFActivityOwner", "WFempTarget", false, "oWinDlg")
			},
			onHide: function() {
				this.destroyDescendants()
			}
		});
		dojo.body().appendChild(a.domNode)
	}
	a.set("href","/HTOA/workflow/htmWFSelectUser.html");
	a.show()
}
function goSelectReceiveUser() {
	var a = dijit.byId('oWinDlg');
	if (a == null) {
		a = new dijit.Dialog({
			title: "\u9009\u62E9\u5904\u7406\u4EBA",
			id: "oWinDlg",
			onDownloadEnd: function() {
				fnAlternateSelectValue("WFReceiveObject", "WFempTarget", false, "oWinDlg")
			},
			onHide: function() {
				this.destroyDescendants()
			}
		});
		dojo.body().appendChild(a.domNode)
	}
	a.set("href", "/" + gCurDB + "/htmWFSelectReceiveUser?ReadForm");
	a.show()
}